#!/usr/bin/env python3.10
# -*- encoding: utf-8 -*-
'''
@File    :   api.py
@Time    :   2023/09/04 10:55:59
@Author  :   windstarry 
@Version :   1.0
'''
# here put the import lib

from ninja import NinjaAPI

from ninja.errors import AuthenticationError
from ninja.responses import JsonResponse
from apps.user.views import router as user_router
from apps.product.views import router as product_router
from apps.user.addr_views import router as addr_router
from apps.order.views import router as order_router

app = NinjaAPI(title="DjangoNinja-外卖H5",
               description="使用DjangoNinja实现外卖项目")

app.add_router("/user", router=user_router)
app.add_router("", router=product_router)
app.add_router("/addressBook", router=addr_router)
app.add_router("/order", router=order_router)

@app.get("/")
def index(request):
    return "Hello Django Ninja"

@app.exception_handler(AuthenticationError)
def handle_auth_error(request, exc):
    # H5 跳转到登录页
    return JsonResponse(dict(msg="NOTLOGIN", code=0, data=None))